import api from './api';

const plagiarismService = {
  /**
   * 上传多个作业文件进行查重分析
   * @param {File[]} files - 用户选择的文件数组
   * @param {Function} onUploadProgress - 上传进度回调
   * @returns {Promise<Array>} - 包含相似度报告的数组
   */
  async analyzeSubmissions(files, onUploadProgress) {
    const formData = new FormData();
    files.forEach(file => {
      formData.append('files', file);
    });

    try {
      const response = await api.post('/api/plagiarism/analyze', formData, {
        headers: {
          'Content-Type': 'multipart/form-data',
        },
        onUploadProgress,
      });
      return response.data;
    } catch (error) {
      console.error('[PlagiarismService] 分析失败:', error);
      const errorMessage = error.response?.data?.error || error.message || '请求服务器失败';
      throw new Error(errorMessage);
    }
  },
};

export default plagiarismService;